package edu.zut.cs.javaee.manager.register.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.stereotype.Service;

import edu.zut.cs.javaee.manager.base.service.impl.GenericTreeManagerImpl;
import edu.zut.cs.javaee.manager.register.dao.RegisterDao;
import edu.zut.cs.javaee.manager.register.domain.Register;
import edu.zut.cs.javaee.manager.register.service.RegisterManager;

/**
 * Managerdao
 * @author 57281
 *
 */
@Service(value="registerManager")
public class RegisterManagerImpl extends GenericTreeManagerImpl<Register,Long> implements RegisterManager {
	
	RegisterDao registerDao;

	@Autowired
	public void setRegisterDao(RegisterDao registerDao) {
		this.registerDao = registerDao;
		this.dao=this.registerDao;
	}

	/**
	 * @Override
	 * 
	 * findByName by department.name
	 */

	@Override
	public List<Register> findByName(String sname) {
		Register querydepart=new Register();
		querydepart.setEntityName(sname);
		ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
				.withStringMatcher(StringMatcher.CONTAINING) // 改变默认字符串匹配方式：模糊查询
				.withMatcher("sname", GenericPropertyMatchers.contains()) //采用“开始匹配”的方式查询
				.withIgnorePaths("dateCreated", "dateModified"); // 忽略属性：是否关注。因为是基本类型，需要忽略掉
		// 创建实例并查询
		Example<Register> ex = Example.of(querydepart, matcher);
		List<Register> result=this.registerDao.findAll(ex);
		return result;
	}
}
